package org.example;

import com.sun.net.httpserver.HttpServer;
import org.example.httphandler.RedirectRequestHandler;
import org.example.httphandler.ResourceHandler;

import java.io.IOException;
import java.net.InetSocketAddress;

/**
 * @author 胡帅博
 * @date 2021/6/10 21:33
 */
public class App{
    /**
     * 很关键，这个可以用来删除ws
     * chrome://serviceworker-internals/
     */
    //http://localhost:8888/redirect?url=http%3A%2F%2Fwoshibabadebaba.gitee.io%2Ffoodgame%2F&needHook=1


    //http://localhost:8888/redirect?url=https%3A%2F%2Fsegmentfault.com%2F&needHook=1
    public static void main(String[] args) throws IOException {
        HttpServer server = HttpServer.create(new InetSocketAddress(8888), 1000);

        //默认非准确模式，并且每个请求都会便利所有上线问，找到最长匹配那个
        server.createContext("/redirect", new RedirectRequestHandler());
        server.createContext("/", new ResourceHandler());
        server.setExecutor(null); // creates a default executor
        server.start();
    }
}
